﻿<ComClass(ClsDevCylinder.ClassId, ClsDevCylinder.InterfaceId, ClsDevCylinder.EventsId)>
Public Class ClsDevCylinder

#Region "COM GUID"
    ' 这些 GUID 提供此类的 COM 标识 
    ' 及其 COM 接口。若更改它们，则现有的
    ' 客户端将不再能访问此类。
    Public Const ClassId As String = "38d7f04b-f094-4801-9af2-0168b6062e80"
    Public Const InterfaceId As String = "c74fb0d8-dd71-47eb-9e26-bb8bb397c3c2"
    Public Const EventsId As String = "2d932b51-46bb-4e91-8bb8-e090338ec85f"
#End Region

    ' 可创建的 COM 类必须具有一个不带参数的 Public Sub New() 
    ' 否则， 将不会在 
    ' COM 注册表中注册此类，且无法通过
    ' CreateObject 创建此类。
    Public Sub New()
        MyBase.New()
    End Sub

#Region "属性字段"

    Private _r As Double
    Public Property 内径() As Double
        Get
            Return _r
        End Get
        Set(value As Double)
            _r = value
        End Set
    End Property

    Private _thk As Double
    Public Property 壁厚() As Double
        Get
            Return _thk
        End Get
        Set(value As Double)
            _thk = value
        End Set
    End Property

    Private _h As Double
    Public Property 高度() As Double
        Get
            Return _h
        End Get
        Set(value As Double)
            _h = value
        End Set
    End Property
#End Region

#Region "构造函数"
    Public Sub Creator(innerRadius As Double, height As Double, Optional thk As Double = 0#)
        Me.内径 = innerRadius
        Me.壁厚 = thk
        Me.高度 = height
    End Sub

#End Region

#Region "画出各种情况展开图"
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="curLayout"></param>
    ''' <param name="insertPoint"></param>
    ''' <returns></returns>
    Public Function 画出圆柱的展开图(curLayout As Object, insertPoint As ClsPoint2d) As Object
        Dim rec As New ClsRectangle
        Dim length = (Me.内径 * 2 + Me.壁厚) * Math.PI
        Dim ce = insertPoint.PolarPoint(0, 0.5 * length).PolarPoint(Math.PI * 0.5, Me.高度 * 0.5)
        rec.Creator(ce, Me.高度, length)


        Dim rtn = rec.ToAcadEntity(curLayout)
        Dim helepr As New ClsACadObjectEx

        helepr.SetClassXdataToObject(rtn, Me)

        Return rtn

    End Function

    Public Function 画出斜面截断圆柱的断面(curLayout As Object, 斜截面与底面圆夹角 As Double, insertPoint As ClsPoint2d, Optional 等分份数 As Integer = 64) As Object

        Dim 中性面的半径 = (Me.内径 * 2 + Me.壁厚) * 0.5
        Dim plineVertexs As New List(Of ClsLwPolylineVertex)
        For index = 0 To 等分份数
            Dim curAng = index * Math.PI * 2.0 / 等分份数
            Dim curPnt As New ClsPoint2d With {
                .X = insertPoint.X + 中性面的半径 * Math.Cos(curAng),
                .Y = insertPoint.Y + (中性面的半径 * Math.Sin(curAng)) / Math.Cos(斜截面与底面圆夹角 * Math.PI / 180)
                }
            plineVertexs.Add(curPnt.ToLwPolyLineVertext())
        Next

        Dim pline As New ClsLwPolyLine With {
            .Vertexs = plineVertexs.ToArray()
        }

        Dim rtn = pline.DrawToAcad(curLayout)
        Dim helepr As New ClsACadObjectEx
        Dim col As New Collection From {
            NameOf(斜截面与底面圆夹角) & "====>" & 斜截面与底面圆夹角,
            NameOf(等分份数) & "====>" & 等分份数
        }

        helepr.SetClassXdataToObject(rtn, Me, col)
        Return rtn
    End Function

    Public Function 画出斜面截断圆柱的展开图(curLayout As Object, 斜截面与底面圆夹角 As Double, insertPoint As ClsPoint2d, Optional 等分份数 As Integer = 64) As Object

        Dim 中性面的半径 = (Me.内径 * 2 + Me.壁厚) * 0.5

        Dim plineVertexs As New List(Of ClsLwPolylineVertex)

        Dim sp As ClsLwPolylineVertex = insertPoint.ToLwPolyLineVertext()

        Dim sp1 As ClsLwPolylineVertex = insertPoint.PolarPoint(Math.PI * 0.5, Me.高度).ToLwPolyLineVertext()

        'insertPoint.PolarPoint(Math.PI * 0.5, Me.高度 + 中性面的半径 * Math.Tan(斜截面与底面圆夹角 * Math.PI / 180)).ToLwPolyLineVertext()

        plineVertexs.AddRange({sp, sp1})

        For index = 0 To 等分份数
            Dim arcCenterRad = (index / 等分份数 * 1.0#) * 2 * Math.PI
            Dim curAng = index * Math.PI * 2.0 / 等分份数
            Dim curPnt As New ClsPoint2d With {
                .X = sp1.Position.X + 中性面的半径 * arcCenterRad,
                .Y = sp1.Position.Y + 中性面的半径 * Math.Cos(arcCenterRad) * Math.Tan(斜截面与底面圆夹角 * Math.PI / 180)
                }
            plineVertexs.Add(curPnt.ToLwPolyLineVertext())
        Next

        Dim sp2 As ClsLwPolylineVertex = plineVertexs(plineVertexs.Count - 1).Position.PolarPoint(Math.PI * 1.5, Me.高度 + 中性面的半径 * Math.Tan(斜截面与底面圆夹角 * Math.PI / 180)).ToLwPolyLineVertext()

        plineVertexs.Add(sp2)

        plineVertexs.Add(plineVertexs(0))

        Dim pline As New ClsLwPolyLine With {
            .Vertexs = plineVertexs.ToArray()
        }

        Dim rtn = pline.DrawToAcad(curLayout)
        Dim helepr As New ClsACadObjectEx
        Dim col As New Collection From {
            NameOf(斜截面与底面圆夹角) & "====>" & 斜截面与底面圆夹角,
            NameOf(等分份数) & "====>" & 等分份数
        }

        helepr.SetClassXdataToObject(rtn, Me, col)

        Return rtn
    End Function




#End Region


End Class


